<?php
	/**
	 * 获取goods列表
	 */
    class GoodsList extends APIBase {
		
		public $tag = "GoodsList";
		public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			return true;
		}

		public function logic() {
			$keys = $this->cache_redis->lRange("lg:ids", 0, -1);
			$type = $this->param['type'];
			$playerID = $this->uid;
			/*
			//获取玩家背包数据
			$backpacklist = $this->cache_redis->keys("hbackpack:$playerID:*");
		    //去除默认道
			$propArr = array();
			for($i=0;$i<count($backpacklist);$i++){
				$backpack = $this->cache_redis->hGetAll("hbackpack:$playerID:".$i);
				if($backpack['count']!=-1&&$backpack['type']!=1){//去掉默认的表情动作场景与房卡
					$propArr[] = $backpack['propid'];
				}
			}
            
			$hadprop = array();//背包已有的道具,不能购买
			*/
			$goodses = array();
			foreach ($keys as $key) {
				$goods = $this->cache_redis->hMGet("hg:{$key}", array("id", "name","desc","type","buy_money","money", "give_money","propid"));
				$goods["type"] = (int)$goods["type"];
				if($type==1){
					if ($goods["type"] == 1) { //商城商品标识 type=1,钻石
						$gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
					}
				}elseif($type==2 ||$type==3){
				   if ($goods["type"] == 2 ||$goods["type"] == 3) { //商城商品标识 type=2,独立型房卡,type=3,共付型房卡
						$gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
					}
					
				}elseif($type==4){//表情道具
					if($goods["type"]==4){
						/*
						if(in_array((int)$goods['propid'],$propArr)){
							$hadprop[] = (int)$goods['id'];
						}
						*/
						$gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$gds["type"] = (int)$goods["type"];
						$goodses[] = $gds;
					}
				}elseif($type==5){//动作道具
					if($goods["type"]==5){
						/*
						if(in_array((int)$goods['propid'],$propArr)){
							$hadprop[] = (int)$goods['id'];
						}
						*/
						$gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
					}
				}elseif($type==6){//场景道具
					if($goods["type"]==6){
						/*
						if(in_array((int)$goods['propid'],$propArr)){
							$hadprop[] = (int)$goods['id'];
						}
						*/
						$gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
					}
				}elseif($type==7){//购买vip
				    if($goods["type"]==7){
					    $gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
				    }				
					
			    }elseif($type==8){//购买金币
				    if($goods["type"]==8){
					    $gds["id"] = (int)$goods["id"];
						$gds["name"] = (string)$goods["name"];
						$gds["desc"] = (string)$goods["desc"];
						$gds["buy_money"] = (float)$goods["buy_money"];
						$gds["money"] = (int)$goods["money"];
						$gds["give_money"] = (int)$goods["give_money"];
						$goodses[] = $gds;
				    }
                }
            }
			
			$this->returnData(array('goodses' => $goodses,'type'=>$type));
/*			
			if(!empty($hadprop)){
				$this->returnData(array('goodses' => $goodses,'hadprop'=>$hadprop));
			}else{
				$this->returnData(array('goodses' => $goodses,'hadprop'=>""));
			}
*/			
		}
		
    	public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
